var pageNum = 1;
var pageSize = 15;
var searchValue = "";

$(function () {
    init();
    window.onresize=function(){
        var h = $(window).height();
        var h1 = $(".header").height();
        var h2 = $(".searchmain").height();
        var productContentH = h - h1 - h2 - 40 - 30;

        if(productContentH<623){
            productContentH = 623;
        }

        $(".product-content").css("height", productContentH + "px");//修改下方高度
        $("#pdfArea").css("height", productContentH - 100 + "px");//修改下方高度
        var w = $(".product-content").width();
        var liW = (w/3)  - 36;
        if($(".paperUlLi").length <= 0){
            $(".paper-new li").css("width", liW + "px");//修改试卷显示宽度
        }
        $(".p15").css("width", liW - 83 + "px");//修改试卷显示宽度
    }
});

function init(){
    var s = window.location.search;
    s = s.substring(s.indexOf("?") + 1 , s.length);
    searchValue = s;
    // var h = $(window).height();
    // $("#testT").css("height", h + "px");
    getWordList(pageNum,pageSize,searchValue);
}

function getWordList(pageNum,pageSize,value){
    // changeContentCss();
    $.ajax({
        // url: "/sjgl/sentence/getList?sentence=" + value + "&pageNum=" + wordNum + "&pageSize=" + pageSize,
        url: "/sjgl/sentence/getList?" + value + "&pageNum=" + pageNum + "&pageSize=" + pageSize,
        type: "GET",
        dataType: "json",
        error: function (e) {
            console.log(e);
        },
        success: function (data) {
            if(!data.content || data.content.length == 0){
                nodataShow();
            }else{
                wordsList = data.content;
                var totalElements = data.totalElements;
                var totalPages = data.totalPages;
                fillWordContent(data);
                fillPageList(pageNum,pageSize,totalPages,totalElements);
            }

        }
    });
}

function fillWordContent(data){
    var html = '';
    for(var i = 0; i < data.content.length; i++){
        var title = data.content[i].sentence;
        var paperName = title;
        if(paperName.toString().length  > 50){
            paperName = paperName.toString().substring(0,50) + "...";
        }

        var paper_id = data.content[i].paper_id;
        html += '<li class="border pdfclick">' +
            '<div class="new-mark"><em>句</em></div>' +
            '<div class="iblock p15 new-cont" style="font-size: 15px">' +
            '<div>' +
            '<a class="paper-pdf" href="javascript:void(0)" title="'+title+'">'+paperName+'</a>' +
            '</div>' +
            '</div>' +
            '</li>';
    }
    $(".paper-index-list").html(html);
    var w = $(".paper-index-list").width();
    var liW = (w/3)  - 36;
    $(".paper-new li").css("width", liW + "px");//修改试卷显示宽度
    $(".p15").css("width", liW - 83 + "px");//修改试卷显示宽度
    $(".p15").css("height", "50px");

}

function fillPageList(pageNo,numPerPage,totalPage,totalSize){
    $("#pageList").show();
    if(totalSize > 0){
        $("#page").paging({
            pageNo: pageNo,
            numPerPage:numPerPage,
            totalPage: totalPage,
            totalSize: totalSize,
            callback: function(num) {
                pageNum = num;
                getWordList(pageNum, pageSize, searchValue);
            }
        });
    }else{
        $(".page_div").html("");
    }
}

function nodataShow(){
    $(".paper-index-list").html("<p style='font-size: 18px'>无查询结果</p>");
    $("#pageList").hide();
}